package eteam.aps.controller;

import eteam.aps.common.R;
import eteam.aps.common.exceptions.BusinessException;
import eteam.aps.common.helper.Helper;
import eteam.aps.model.dto.ProductPreserveDto;
import eteam.aps.model.vo.pruduct_process.ProductProcessVo;
import eteam.aps.service.ProductPreserveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 工序维护 控制层
 *
 * @author LiuLei
 */
@RestController
@RequestMapping("ppc")
@Api(tags = "工序维护")
public class ProductPreserveController {

    @Autowired
    private ProductPreserveService productPreserveService;

    @PostMapping("/ppins")
    @ApiOperation("新增产品工序维护")
    @ApiImplicitParam(name = "proInv", value = "产品编号")
    public R<Integer> ppInsert(String proInv) throws Exception {
        if (Helper.isEmpty(proInv)) throw new BusinessException(HttpStatus.BAD_REQUEST, "产品编号不能为空！");
        return R.success(productPreserveService.ppInsert(proInv));
    }

    @PostMapping("/pppins")
    @ApiOperation("新增制令工序维护")
    @ApiImplicitParam(name = "mocInv", value = "制令编号")
    public R<Integer> pppInsert(String mocInv) throws Exception {
        if (Helper.isEmpty(mocInv)) throw new BusinessException(HttpStatus.BAD_REQUEST, "制令编号不能为空！");
        return R.success(productPreserveService.pppInsert(mocInv));
    }

    @PostMapping("/ppdel")
    @ApiOperation("删除产品工序维护")
    @ApiImplicitParam(name = "ids", value = "产品内码（多个用,隔开）")
    public R<Integer> ppDelete(String ids) {
        if (Helper.isEmpty(ids)) throw new BusinessException(HttpStatus.BAD_REQUEST, "产品内码不能为空！");
        if (ids.endsWith(",")) ids = ids.substring(0, ids.length() - 1);
        return R.success(productPreserveService.ppDelete(ids));
    }

    @PostMapping("/pppdel")
    @ApiOperation("删除制令工序维护")
    @ApiImplicitParam(name = "ids", value = "制令内码（多个用,隔开）")
    public R<Integer> pppDelete(String ids) {
        if (Helper.isEmpty(ids)) throw new BusinessException(HttpStatus.BAD_REQUEST, "制令内码不能为空！");
        if (ids.endsWith(",")) ids = ids.substring(0, ids.length() - 1);
        return R.success(productPreserveService.pppDelete(ids));
    }

    @PostMapping("/ppupd")
    @ApiOperation("修改产品工序维护")
    @ApiImplicitParam(name = "ProductPreserveDto", value = "工序维护修改")
    public R<Integer> ppUpdate(@RequestBody ProductPreserveDto preserveDto) throws Exception {
        if (preserveDto == null) throw new BusinessException(HttpStatus.BAD_REQUEST, "参数非法异常");
        if (Helper.isEmpty(preserveDto.getId())) throw new BusinessException(HttpStatus.BAD_REQUEST, "产品内码不能为空！");
        return R.success(productPreserveService.ppUpdate(preserveDto));
    }

    @PostMapping("/pppupd")
    @ApiOperation("修改制令工序维护")
    @ApiImplicitParam(name = "ProductPreserveDto", value = "工序维护修改")
    public R<Integer> pppUpdate(@RequestBody ProductPreserveDto preserveDto) throws Exception {
        if (preserveDto == null) throw new BusinessException(HttpStatus.BAD_REQUEST, "参数非法异常");
        if (Helper.isEmpty(preserveDto.getId())) throw new BusinessException(HttpStatus.BAD_REQUEST, "产品内码不能为空！");
        return R.success(productPreserveService.pppUpdate(preserveDto));
    }

    @PostMapping("/ppsel")
    @ApiOperation("查询产品工序维护")
    @ApiImplicitParam(name = "proInv", value = "产品编码")
    public R<List<ProductProcessVo>> ppList(String proInv) {
        if (Helper.isEmpty(proInv)) throw new BusinessException(HttpStatus.BAD_REQUEST, "产品编号不能为空！");
        return R.success(productPreserveService.ppList(proInv));
    }

    @PostMapping("/pppsel")
    @ApiOperation("查询制令工序维护")
    @ApiImplicitParam(name = "mocInv", value = "制令编码")
    public R<List<ProductProcessVo>> pppList(String mocInv) {
        if (Helper.isEmpty(mocInv)) throw new BusinessException(HttpStatus.BAD_REQUEST, "制令编号不能为空！");
        return R.success(productPreserveService.pppList(mocInv));
    }


}
